package Z.dailyExercise.April;

public class _48旋转图像 {
    /**
     * 思想转化：别从一圈一圈的看 从行转变来看
     * 第i行转成了倒数第i列
     * @param matrix
     */

    public void rotate(int[][] matrix) {
        int n = matrix.length;
        int[][] temp = new int[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                temp[j][n-1-i] = matrix[i][j];
            }

        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                 matrix[i][j] = temp[i][j];
            }

        }

    }
    /**
     * 原地修改，使用翻转代替旋转
     * 旋转= 上下翻转+主对角线翻转
     */
    public void rotate1(int[][] matrix){
        int  n = matrix.length;

        for (int i =0;i<n/2;i++){
            for (int j = 0; j < n; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[n-1-i][j];
                matrix[n-1-i][j] = temp;

            }
        }

        for (int i =0;i<n;i++){
            for (int j = i+1; j < n; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;

            }
        }



    }
}
